package com.unitd.modules.gen.entity;

import com.google.common.collect.Lists;
import com.unitd.comm.entity.SysEntity;
import com.unitd.frame.comm.utils.StringUtils;
import org.hibernate.validator.constraints.Length;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.util.List;

/**
 * @desc 代码模板表
 * @filename GenTemplate.java
 * @copyright www.unitd.com
 * @author Hudan
 * @version 1.0 
 * @date 2017-04-29
 */ 
@Table(name = "gen_template")
@XmlRootElement(name="template")
public class GenTemplate extends SysEntity {

	/** 名称 */
	private String name;
	/** 分类 */
	private String category;
	/** 生成文件路径 */
	@Column(name = "file_path")
	private String filePath;
	/** 生成文件名 */
	@Column(name = "file_name")
	private String fileName;
	/** 内容 */
	private String content;

	/**
	 * @desc 构造方法 GenTemplate
	 */
	public GenTemplate(String id, String name, String category, String filePath, String fileName, String createBy, java.util.Date createDate, String updateBy, java.util.Date updateDate, String remarks, String delFlag, String content) {
		this.id = id;
		this.name = name;
		this.category = category;
		this.filePath = filePath;
		this.fileName = fileName;
		this.createBy = createBy;
		this.createDate = createDate;
		this.updateBy = updateBy;
		this.updateDate = updateDate;
		this.remarks = remarks;
		this.delFlag = delFlag;
		this.content = content;
	}

	/**
	 * @desc 构造方法 GenTemplate
	 */
	public GenTemplate() {
		super();
	}

	/**
	 * @desc 获取名称
	 * @return name - 名称
	 */
	@Length(min = 1, max = 200)
	public String getName() {
		return name;
	}

	/**
	 * @desc 设置名称
	 * @param name 名称
	 */
	public void setName(String name) {
		this.name = name == null ? null : name.trim();
	}

	/**
	 * @desc 获取分类
	 * @return category - 分类
	 */
	public String getCategory() {
		return category;
	}

	/**
	 * @desc 设置分类
	 * @param category 分类
	 */
	public void setCategory(String category) {
		this.category = category == null ? null : category.trim();
	}

	/**
	 * @desc 获取生成文件路径
	 * @return file_path - 生成文件路径
	 */
	public String getFilePath() {
		return filePath;
	}

	/**
	 * @desc 设置生成文件路径
	 * @param filePath 生成文件路径
	 */
	public void setFilePath(String filePath) {
		this.filePath = filePath == null ? null : filePath.trim();
	}

	/**
	 * @desc 获取生成文件名
	 * @return file_name - 生成文件名
	 */
	public String getFileName() {
		return fileName;
	}

	/**
	 * @desc 设置生成文件名
	 * @param fileName 生成文件名
	 */
	public void setFileName(String fileName) {
		this.fileName = fileName == null ? null : fileName.trim();
	}

	/**
	 * @desc 获取内容
	 * @return content - 内容
	 */
	public String getContent() {
		return content;
	}

	/**
	 * @desc 设置内容
	 * @param content 内容
	 */
	public void setContent(String content) {
		this.content = content == null ? null : content.trim();
	}

	@XmlTransient
	public List<String> getCategoryList() {
		if (category == null) {
			return Lists.newArrayList();
		} else {
			return Lists.newArrayList(StringUtils.split(category, ","));
		}
	}

	public void setCategoryList(List<String> categoryList) {
		if (categoryList == null) {
			this.category = "";
		} else {
			this.category = "," + StringUtils.join(categoryList, ",") + ",";
		}
	}
}